'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  app.beforeStart(async () => {
    await app.model.sync({ alter: true });//force  false 为不覆盖 true会删除再创建; alter true可以 添加或删除字段;
  });
  const { router, controller,jwt , io } = app;

  router.get('/', controller.home.index);
  //登录设置
  router.post('/user/login', controller.login.login);
  router.post('/user/register', controller.login.register);
  // 获取账号信息
  router.get('/userList', controller.user.getUserList);
  router.post('/saveUser', controller.user.saveUser);
  router.post('/modifyUser', controller.user.modifyUser);
  router.get('/findUser', controller.user.findUser);
  router.post('/deleteUser', controller.user.deleteUser);
  router.post('/userAddRole', controller.user.userAddRole);
  router.get('/findUserSelfRoles', controller.user.findUserSelfRoles);
  

  //笔记相关
  router.get('/noteList', controller.note.getNoteList);
  router.get('/selfNoteList', controller.note.getSelfNoteList);
  router.post('/saveNote', controller.note.saveNote);
  router.post('/deleteNote', controller.note.deleteNote);
  router.post('/findNote', controller.note.findNote);
  router.post('/modifyNote', controller.note.modifyNote);

  //视频相关
  router.get('/videoList', controller.video.getVideoList);
  router.post('/saveVideo', controller.video.saveVideo);
  router.post('/findVideo', controller.video.findVideo);
  router.post('/modifyVideo', controller.video.modifyVideo);
  router.post('/deleteVideo', controller.video.deleteVideo);

  //角色相关
  router.get('/getRoleList', controller.role.getRoleList);
  router.post('/modifyRole', controller.role.modifyRole);
  router.post('/deleteRole', controller.role.deleteRole);
  router.get('/findRoleSelfPermissions', controller.role.findRoleSelfPermissions);
  router.post('/roleAddPermission', controller.role.roleAddPermission);
  

  //菜单权限
  router.get('/getPermissionList', controller.permission.getPermissionList);
  router.get('/getSelfPermissionList', controller.permission.getSelfPermissionList);
  router.post('/modifyPermission', controller.permission.modifyPermission);
  router.post('/deletePermission', controller.permission.deletePermission);
 

  //工具接口
  router.post("/upload", controller.utils.uploadFiles);
  
  
  // app.io.route('deploy', app.io.controller.deploy.res);
  app.io.of('/').route('deploy', app.io.controller.deploy.res);
};
